import math

from openpyxl import  Workbook

# wb = Workbook()
# ws = wb.active
# ws.title = "测试读写操作"
# for i in range(10):
#     ws["A%d" % (i+1)].value = i +1
# ws["E1"].value = "=SUM(A:A)"
# wb.save('保存在一个excel.xlsx')

wb = Workbook()
sheet = wb.active
sheet.title = '测试读写Excel操作'
col_names = ['数字', '平方', '立方', '阶乘', '几何级数']
for index, col in enumerate('ABCDE'):
    print(index,col)
    sheet[f'{col}1'] = col_names[index]
for num in range(1, 11):
    sheet[f'A{num + 1}'] = num
    sheet[f'B{num + 1}'] = num ** 2
    sheet[f'C{num + 1}'] = num ** 3
    sheet[f'D{num + 1}'] = math.factorial(num)
    sheet[f'E{num + 1}'] = 2 ** num
# wb.save('使用openpyxl.xlsx')